// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import "@/assets/style/common.scss"
import Util from './lib/utils'
import store from './store'
import axios from 'axios'
import Qs from 'qs'
import io from 'socket.io-client'
import i18n from './lang/lang'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
Vue.use(Util)
Vue.use(ElementUI)
// Vue.use(axios)

const socket = io.connect('www.bibex.org')
// if(localStorage.getItem('socketPort')){
//   var socket = io.connect('http://www.bitex.ren:'+ localStorage.getItem('socketPort'))
// }else{
// 	axios.get('/api/env.json').then(res=>{
//     localStorage.setItem('socketPort',res.data.socket_io_port);
//     var socket = io.connect('http://www.bitex.ren:'+ res.data.socket_io_port);
// 	})
// }
Vue.prototype.axios = axios;
Vue.prototype.qs = Qs;
Vue.prototype.$socket = socket;
window.eventBus = new Vue();//eventBus传值

let bus = new Vue()//bus传值
Vue.prototype.bus = bus

Vue.prototype.$makeSocketId = function () {// 随机id
	var d = new Date().getTime()
	var ran = parseInt(Math.random() * 888 + 101 + '');
	d = d + '' + ran;
	return d;
}
Vue.prototype.openLoading = function() {//loading层
  const loading = this.$loading({
    lock: true,
    text: '正在加载...',
    spinner: 'el-icon-loading',
    background: 'rgba(0, 0, 0, 0.5)',
    target: '.sub-main',
    body: true,
    customClass: 'mask'
  })
  setTimeout(function () {
    loading.close();
  },5000)
  return loading;
}

Vue.filter('Fixed2', function (value) {//  注册过滤器
  return Number(value).toFixed(2);
})
Vue.filter('Fixed4', function (value) {
  return Number(value).toFixed(4);
})
Vue.filter('Fixed8', function (value) {
  return Number(value).toFixed(8);
})
axios.interceptors.response.use(response=>{
	if(response.data.type == '999'){
    Vue.prototype.$message({
      message:'请登录'
    });
    return false;
    setTimeout(function(){
      router.replace({  
        path: '/login',  
        query: {redirect: router.currentRoute.fullPath}//登录成功后跳入浏览的当前页面  
      })  
    })
	}
	return response
})
console.log(store.getters.getToken)
axios.interceptors.request.use(function (config) {
  let token = store.getters.getToken;
	if (token) {
		config.headers['Authorization'] = token;
	}
	return config;
})
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';

Vue.config.productionTip = false
// Vue.use(VueAwesomeSwiper)
/* eslint-disable no-new */
new Vue({
  el: '#app',
  i18n,
  router,
  store,//使用store
  components: { App },
  template: '<App/>'
})
